<template>
  <div>
    <a-card :bordered="false" :bodyStyle="tstyle">
      <div class="table-page-search-wrapper" v-if="hasPerm('sysTimersLog:page')">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="bean名称">
                <a-input v-model="queryParam.beanName" allow-clear placeholder="请输入bean名称"/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="resetParam()">重置</a-button>
              </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false">
      <s-table
        ref="table"
        :columns="columns"
        :data="loadData"
        :alert="false"
        :rowKey="(record) => record.id"

      >
        <template class="table-operator" slot="operator" v-if="hasPerm('sysTimersLog:delete')" >

          <a-popconfirm v-if="hasPerm('sysTimersLog:deleteAll')" @confirm="clear()" placement="top" title="确认清空日志？">
            <a-button type="danger" ghost>清空日志</a-button>
          </a-popconfirm>
        </template>


        <span slot="status" slot-scope="text, record">
            {{ 'success_status' | dictType(text) }}
        </span>
      </s-table>

    </a-card>
  </div>
</template>
<script>
  import { STable, XDown } from '@/components'
  import { sysTimersLogPage, deleteAll } from '@/api/modular/system/sysTimersLogManage'

  export default {
    components: {
      STable,
      XDown
    },
    filters:{

    },
    data () {
      return {
        // 查询参数
        queryParam: {},
        // 表头
        columns: [
          {
            title: '任务说明',
            align: 'center',
            dataIndex: 'jobDetail'
          },
          {
            title: 'bean名称',
            align: 'center',
            dataIndex: 'beanName'
          },
          {
            title: '参数',
            align: 'center',
            dataIndex: 'params'
          },
          {
            title: '任务状态   ',
            align: 'center',
            dataIndex: 'status',
            scopedSlots: { customRender: 'status' }
          },
          {
            title: '失败信息',
            align: 'center',
            dataIndex: 'error'
          },
          {
            title: '耗时(单位：毫秒)',
            align: 'center',
            dataIndex: 'times'
          },
          {
            title: '运行时间',
            align: 'center',
            dataIndex: 'currentRunningTime'
          }
        ],
        tstyle: { 'padding-bottom': '0px', 'margin-bottom': '10px' },
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return sysTimersLogPage(Object.assign(parameter, this.queryParam)).then((res) => {
            return res.data
          })
        },
        selectedRowKeys: [],
        selectedRows: [],

      }
    },
    created () {

    },
    methods: {
      resetParam(){
        this.queryParam = {};
        this.$refs.table.refresh(true)
      },

      /**
       * 清空
       */
      clear () {
        deleteAll().then(res=>{
          this.$refs.table.refresh(true)
        }).catch(err=>{

        })

      },

    }
  }
</script>
<style lang="less">
  .table-operator {
    margin-bottom: 18px;
  }
  button {
    margin-right: 8px;
  }
</style>
